home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / console / svgatext.3 / svgatext / SVGATextMode-1.3 / grabmode.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-21  |  8.7 KB  |  265 lines

  1. /*  SVGATextMode -- An SVGA textmode manipulation/enhancement tool
  2.  *
  3.  *  Copyright (C) 1995,1996  Koen Gadeyne
  4.  *
  5.  *  This program is free software; you can redistribute it and/or modify
  6.  *  it under the terms of the GNU General Public License as published by
  7.  *  the Free Software Foundation; either version 2 of the License, or
  8.  *  (at your option) any later version.
  9.  *
  10.  *  This program is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *  GNU General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU General Public License
  16.  *  along with this program; if not, write to the Free Software
  17.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20.  
  21. /***
  22.  *** grabmode/clockprobe
  23.  ***
  24.  *** This program outputs the current text or graphics mode, in an SVGATextMode (or XF86Config-like) compatible line
  25.  *** Should work on ANY VGA card, since it only uses standard VGA registers
  26.  ***
  27.  ***/
  28.  
  29. #include <stdio.h>
  30. #include <string.h>
  31. #include <stdlib.h>
  32. #include <unistd.h>
  33.  
  34. #include "misc.h"
  35. #include "messages.h"
  36. #include "modedata.h"
  37. #include "mode_msg.h"
  38. #include "string_ops.h"
  39.  
  40. #ifdef DOS
  41. #define get_VGA_io_perm(x)
  42. #undef Renounce_SUID
  43. #define Renounce_SUID
  44. extern int optind;
  45. #endif
  46.  
  47. char *CommandName;
  48. bool debug_messages=FALSE;
  49.  
  50. int STM_Options=0;  /* just to keep the compiler happy */
  51.  
  52. #define CLOCKPROBE  1
  53. #define GRABMODE    2
  54.  
  55. void usage(int func)
  56. {
  57.      PMESSAGE(("version %s. (c) 1995,1996 Koen Gadeyne.\n Usage: %s [options] \n"\
  58.      "  Options: -n  Don't program VGA hardware\n"\
  59.      "           -d  print debugging information\n"\
  60.      "           -r  `raw' mode: don't do any guesswork on special modes,\n"\
  61.      "               just print the values as they appear in the VGA registers\n"\
  62.      "           -v  verbose mode (report all special VGA flags for the mode)\n"\
  63.      "           -x <screen width>\n"\
  64.      "           -y <screen height>\n"\
  65.      "              specify screen width and height in pixels when it is known\n"\
  66.      "              beforehand. This reduces the probe's guesswork (and errors).\n"\
  67.      "           -h  print usage information\n"\
  68.      "%s"\
  69.      "  NOTE: All non-standard VGA features could cause bogus results:\n"\
  70.      "         * interlaced modes\n"\
  71.      "         * modes with >= 1024 active lines (like 1280x1024 and up)\n"\
  72.      "         * HiColor (15/16bpp) and TrueColor (24/32bpp) modes\n"\
  73.      "         * modes on cards with special DAC's\n"\
  74.      "        The program will try to detect this and compensate\n"\
  75.      "        (but will issue a warning that the actual VGA timings were adjusted)\n",\
  76.      VERSION, CommandName,\
  77.      (func==GRABMODE) ? \
  78.      "           -X  Output compatible with XF86Config mode line\n"\
  79.      "               (NOTE: grabbed graphic modes are not always correct)\n"\
  80.      "           -T  Output compatible with TextConfig mode line\n"\
  81.      "           -b  Also print blanking information\n"\
  82.      "           -c  Don't probe for pixel clock (just print timing information)\n"\
  83.      :\
  84.      "           -p  print ONLY clock value (for use in scripts, pipes, etc)\n" ));
  85. }
  86.  
  87. /***********************************************************************************************************/
  88.  
  89. int main (int argc, char* argv[])
  90. {
  91.   bool program_hardware=TRUE;
  92.   int Xmode=MODE_UNDEFINED;
  93.   bool showblank=FALSE;
  94.   bool probe_clock=TRUE;
  95.   bool pipeable=FALSE;
  96.   bool raw_mode=FALSE;
  97.   bool verbose=FALSE;
  98.   int i;
  99.   char* commandfilename;
  100.   int c;
  101.   modestruct m;
  102.   int initial_x=-1, initial_y=-1;
  103.   int func;
  104.   
  105.   CommandName = argv[0];
  106.   commandfilename = strrchr(CommandName, '/');
  107.   if (commandfilename) commandfilename++;
  108.   else commandfilename = CommandName;
  109.   func = (!strncasecmp(commandfilename,"grab",4)) ? GRABMODE : CLOCKPROBE;
  110.  
  111.  
  112.  /*
  113.   * command-line argument parsing
  114.   */
  115.  
  116.   while ((c = getopt (argc, argv, "ndrhXTbcpvx:y:")) != EOF)
  117.     switch (c)
  118.     {
  119.       case 'n': program_hardware=FALSE;
  120.                 break;
  121.       case 'd': debug_messages=TRUE;
  122.                 break;
  123.       case 'r': raw_mode=TRUE;
  124.                 break;
  125.       case 'X': Xmode = MODE_GRAPHICS;
  126.                 break;
  127.       case 'T': Xmode = MODE_TEXT;
  128.                 break;
  129.       case 'b': showblank = TRUE;
  130.                 break;
  131.       case 'c': probe_clock = FALSE;
  132.                 break;
  133.       case 'p': pipeable = TRUE;
  134.                 break;
  135.       case 'v': verbose = TRUE;
  136.                 break;
  137.       case 'h': usage(func);
  138.                 exit(0);
  139.                 break;
  140.       case 'x': initial_x=getint(optarg, "X-size preset", 0, 4096);
  141.                 PDEBUG(("X-size on command line = %d\n", initial_x));
  142.                 break;
  143.       case 'y': initial_y=getint(optarg, "Y-size preset", 0, 4096);
  144.                 PDEBUG(("Y-size on command line = %d\n", initial_y));
  145.                 break;
  146.       case '?': usage(func);
  147. #ifndef DOS
  148.                 PERROR(("Bad option '-%c'\n",(char)optopt));
  149. #endif                
  150.                 exit(-1);
  151.                 break;
  152.       default: PERROR(("getopt returned unknown token '%c'.\n",c));
  153.     }
  154.  
  155.  PVERSION;
  156.  
  157. /*
  158.  * start doing something useful
  159.  */
  160.  
  161.  if (!program_hardware) return(0);
  162.  
  163.  PWARNING(("Please be patient. This may take a while (up to 1 minute)\n"));
  164.  
  165.  getmode(&m, probe_clock, raw_mode, initial_x, initial_y);
  166.  
  167.  if (func == CLOCKPROBE)
  168.  {
  169.    if (pipeable)
  170.    {
  171.      printf("%1.2f\n", m.mode_line.pixelClock/1000.0);
  172.    }
  173.    else
  174.    {
  175.      PMESSAGE(("Estimated vertical scanrate = %1.3f Hz.\n", m.mode_line.vfreq/1000.0));
  176.      PMESSAGE(("Estimated horizontal scanrate = %1.3f kHz.\n", m.mode_line.hfreq/1000.0));
  177.      PMESSAGE(("Estimated pixel clock = %1.2f MHz\n", m.mode_line.pixelClock/1000.0));
  178.      if (GMOFLG_ISSET(m,CLOCKDIV2))
  179.        PMESSAGE(("NOTE: actual clock is %1.2f MHz, but it is divided by 2.\n", m.mode_line.pixelClock*2/1000.0));
  180.    }
  181.    return(0);
  182.  }
  183.  
  184.  /*
  185.   * "grabmode" function.
  186.   * From parameters, look for special settings that affect the output
  187.   */
  188.   
  189.   /* auto selection between graphics/text mode if not defined on command line */
  190.   if (Xmode==MODE_UNDEFINED) Xmode = m.txt_gr_mode;
  191.   
  192.  /*
  193.   * Print the mode line
  194.   */
  195.   
  196.  if (Xmode==MODE_TEXT)
  197.    printf("\"%dx%d\"   ", m.mode_line.HDisplay/8, m.mode_line.VDisplay/m.mode_line.FontHeight);
  198.  else 
  199.    printf("\"%dx%d\"   ", m.mode_line.HDisplay, m.mode_line.VDisplay);
  200.  
  201.  if (probe_clock)
  202.    printf("%1.3f", m.mode_line.pixelClock/1000.0);
  203.  else
  204.    printf("***");
  205.          
  206.  printf("   %d %d %d %d   %d %d %d %d   %cHsync %cVsync",
  207.          m.mode_line.HDisplay, m.mode_line.HSyncStart, m.mode_line.HSyncEnd, m.mode_line.HTotal,
  208.          m.mode_line.VDisplay, m.mode_line.VSyncStart, m.mode_line.VSyncEnd, m.mode_line.VTotal,
  209.         (m.mode_line.hpol==POS) ? '+' : '-',
  210.         (m.mode_line.vpol==POS) ? '+' : '-');
  211.         
  212.  if (GMOFLG_ISSET(m,DOUBLESCAN)) printf("  DoubleScan");
  213.  if (GMOFLG_ISSET(m,MULTISCAN)) printf("  %sScan", m.mode_line.FontHeight==2 ? "Double" : "Multi");
  214.  
  215.  if (GMOFLG_ISSET(m,INTERLACE)) printf("  Interlace");
  216.  
  217.  if (Xmode==MODE_TEXT) printf("  font %dx%d", m.mode_line.FontWidth, m.mode_line.FontHeight);
  218.  
  219.  if (probe_clock)    
  220.    printf("   # %1.3fkHz/%1.2fHz\n", m.mode_line.hfreq/1000.0, m.mode_line.vfreq/1000.0);
  221.  else
  222.    printf("\n");
  223.    
  224.  if (showblank)
  225.    printf("#   Blanking: H=%d-%d ; V=%d-%d\n", m.starthbl, m.endhbl, m.startvbl, m.endvbl);
  226.    
  227.  if (verbose)
  228.  {  
  229.    printf("#   Active special VGA register flags: ");
  230.    if (m.mode_flags == 0) printf("none.");
  231.    if (GMOFLG_ISSET(m,DOUBLESCAN))      printf("DOUBLESCAN ");
  232.    if (GMOFLG_ISSET(m,CLOCKDIV2))       printf("CLOCKDIV2 ");
  233.    if (GMOFLG_ISSET(m,MULTISCAN))       printf("MULTISCAN ");
  234.    if (GMOFLG_ISSET(m,BYTEMODE))        printf("BYTEMODE ");
  235.    if (GMOFLG_ISSET(m,WORDMODE))        printf("WORDMODE ");
  236.    if (GMOFLG_ISSET(m,DOUBLEWORDMODE))  printf("DOUBLEWORDMODE ");
  237.    if (GMOFLG_ISSET(m,VERT_DOUBLE))     printf("VERT_DOUBLE ");
  238.    if (GMOFLG_ISSET(m,PCS_DIV2))        printf("PCS_DIV2 ");
  239.    if (GMOFLG_ISSET(m,CNT_BY_2))        printf("CNT_BY_2 ");
  240.    if (GMOFLG_ISSET(m,INTERLACE))       printf("INTERLACE ");
  241.    if (GMOFLG_ISSET(m,SHIFT_CGA256C))   printf("SHIFT_CGA256C ");
  242.    if (GMOFLG_ISSET(m,SHIFT_CGA4C))     printf("SHIFT_CGA4C ");
  243.    printf("\n");
  244.  }  
  245.  
  246.  if (m.remarks!=0)
  247.  {
  248.    PDEBUG(("Remarks mask: 0x%4X\n", m.remarks));
  249.    fputc('\n', stderr);
  250.    PWARNING(("Grabbed mode could be wrong. Below is a list of remarks about it:\n\n"));
  251.    for (i=0; mode_messages[i].msg_mask >0 ; i++)
  252.    {
  253.      if ((m.remarks & (1<<i)) != 0)
  254.      {
  255.        if ((1<<i)==MSG_CLOCK_MEASUREMENTS)
  256.          fprintf(stderr, mode_messages[i].msg_txt,m.valid_measurements);
  257.        else
  258.          fprintf(stderr, mode_messages[i].msg_txt);
  259.        fputc('\n', stderr);
  260.      }
  261.    }
  262.  }
  263.   return(0);
  264. }
  265.